package com.zanbo.clock.model.base.bean;

import com.zanbo.clock.model.code.BaseCodeInterface;
import lombok.Data;

/**
 * @author: zanbo
 * @description: 统一返回值类，所有返回值都为同一类型
 * @date: 上午 11:03 2021-4-26
 */
@Data
public class ResponseBean {
    /**
     * http 状态码
     */
    private int code;
    
    /**
     * http 返回信息
     */
    private String msg;
    
    /**
     * http 返回的数据
     */
    private Object data;
    
    public ResponseBean() {
    
    }
    
    public ResponseBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static ResponseBean success(Object o) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(o);
        responseBean.setCode(200);
        responseBean.setMsg("成功");
        return responseBean;
    }
    
    public static ResponseBean success(String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(null);
        responseBean.setCode(200);
        responseBean.setMsg(msg);
        return responseBean;
    }
    
    public static ResponseBean success(Object o, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(o);
        responseBean.setCode(200);
        responseBean.setMsg(msg);
        return responseBean;
    }
    
    public static ResponseBean success(int code, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setMsg(msg);
        responseBean.setData(null);
        return responseBean;
    }
    
    public static ResponseBean success() {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setData(null);
        responseBean.setCode(200);
        responseBean.setMsg("成功");
        return responseBean;
    }
    
    public static ResponseBean error(int code, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setMsg(msg);
        responseBean.setData(null);
        return responseBean;
    }
    
    public static ResponseBean error(int code, String msg, Object o) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setMsg(msg);
        responseBean.setData(o);
        return responseBean;
    }
    
    
}
